#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#define int long long 
#define x first 
#define y second 
using namespace std;
const int N = 1e5 + 10;
typedef pair<int,int> PII; 
vector<vector<char>> g(N,vector<char>());
int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};

void solve()
{
     int n,m;
     cin >> n >> m;
     for(int i = 0; i < n; i++)
     {
        for(int j = 0; j < m; j++)
        cin >> g[i][j];
     }
     queue<PII> q;
     for(int i = 0; i < n; i++)
     {
        for(int j = 0; j < m; j++)
        {
            if(g[i][j] == 'S') q.push({i , j});
        }
     }
     auto arr1 = g;
     while(! q.empty())
     {
        PII t = q.front();
        q.pop();
        int x1 = t.x, y1 = t.y;
        arr1[x1][y1] = '1';
        for(int i  = 0; i < 4; i++)
        {
            int x2 = x1 + dx[i];
            int y2 = y1 + dy[i];
            if(x2 < 0 || x2 >= n || y2 < 0 || y2 >= m) continue;
            if(g[x2][y2] == '#') continue;
            if(arr1[x2][y2] == '1') continue;
            arr1[x2][y2] = '1';
            q.push({x2,y2});
        }
     }
     
     for(int i = 0; i < n; i++)
     {
        for(int j = 0; j < m; j++)
        {
            if(g[i][j] == 'E') q.push({i,j});
        }
     }
      auto arr2 = g;
      while(! q.empty())
     {
        PII t = q.front();
        q.pop();
        int x1 = t.x, y1 = t.y;
        arr1[x1][y1] = '2';
        for(int i  = 0; i < 4; i++)
        {
            int x2 = x1 + dx[i];
            int y2 = y1 + dy[i];
            if(x2 < 0 || x2 >= n || y2 < 0 || y2 >= m) continue;
            if(g[x2][y2] == '#') continue;
            if(arr1[x2][y2] == '2') continue;
            arr1[x2][y2] = '2';
            q.push({x2,y2});
        }
     }
     vector<int> h1(n,0);
     vector<int> z1(m,0);
     for(int i = 0; i < n; i++)
     {
        for(int j = 0; j < m; j++)
        {
            if(arr1[i][j] == '1') 
            {
                h1[i] = 1;
                z1[i] = 1;
            }
        }
     }
     for(int i = 0; i < n; i++)
     {
        for(int j = 0; j < m; j++)
        {
            if(arr2[i][j] == '2') 
            {
                for(int k = -1; k <= 1; k++)
                {
                    if(i + k >=0 && i + k < n && h1[i + k])
                    {
                        cout << "YES" << endl;
                        return;
                    }
                    if(j + k >= 0 && j + k < n && z1[j + k])
                    {
                        cout << "YES" << endl;
                        return;
                    }
                }
            }
        }
     }
     cout << "NO" << endl;
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    int t = 1;
    /* cin >> t; */
    while(t--) solve();
    return 0;
}